﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using VISS.API.Users;
using NCT.Framework;
using System.Collections.Generic;

namespace VISS.Web.Frontend.Modules.User.Profile {

    public enum EInterestViewType {
        Thumb = 1,
        Detail = 2
    }

    public partial class InterestMePage : System.Web.UI.Page {

        protected EInterestViewType ViewType = EInterestViewType.Thumb;
        protected int TotalRecord = 0;
        protected string Paging;
        protected bool CanSendMessage;

        protected void Page_Load(object sender, EventArgs e) {
            UserContext userContext = LoginFactory.GetCurrentUser();
            if (userContext == null) {
                Response.Redirect("/login");
                return;
            }
            switch (ConvertUtils.ToString(Request.QueryString["viewtype"])) {
                case "thumb":
                    ViewType = EInterestViewType.Thumb;
                    break;
                case "detail":
                    ViewType = EInterestViewType.Detail;
                    break;
                default:
                    ViewType = EInterestViewType.Thumb;
                    break;
            }

            int page;
            string queryString = AppSettings.RootURL + "profile/interest?";
            page = ConvertUtils.ToInt(Request.QueryString["page"], 1);

            int pageSize = 0;
            if (ViewType == EInterestViewType.Thumb) {
                pageSize = AppSettings.PageSizeOfInterestMeThumb;
                queryString += "viewtype=thumb";
            }
            else {
                pageSize = AppSettings.PageSizeOfInterestMeDetail;
                queryString += "viewtype=detail";
            }
            
            List<UserFollowerEnt> result = StructureMapFactory.GetInstance<IUserFollower>().GetByFollowedUserKeyWithPaging(userContext.UserKey, page, pageSize, out TotalRecord);
            idInterestMeDetail.InterestMeProfiles = idInterestMeThumb.InterestMeProfiles = result;

            if ((userContext.Status & EUserStatus.Verified) == EUserStatus.Verified) {
                CanSendMessage = true;
                idInterestMeDetail.CanDoAction = idInterestMeThumb.CanDoAction = true;
            }
            else {
                CanSendMessage = false;
                idInterestMeDetail.CanDoAction = idInterestMeThumb.CanDoAction = false;
            }

            Paging pager = new Paging(TotalRecord);
            pager.QueryString = queryString;
            pager.PerPage = pageSize;
            pager.DisplayParam = "p";
            pager.Param = "page";
            pager.ShowMore = false;
            pager.LinkFormatTemplate = "<div class=\"page\">{0}</div>";
            pager.SelectedPageFormatTemplate = "<div class=\"page selected-page\">{0}</div>";

            Paging = pager.BuildPaging();

            // SEO
            IHeadSeo seo = this.Master as IHeadSeo;
            seo.Title = StringResources.SEO.TitleUserInterest + " | " + userContext.FullName + " | " + StringResources.SEO.TitleDefault;
            seo.Description = StringResources.SEO.DescriptionDefault;
            seo.Keywords = StringResources.SEO.KeywordsDefault;
        }
    }
}
